﻿using System;
using System.Text;
using System.Data;
using System.Collections;
using DataBaseConnection;
using System.Collections.Generic;

namespace DataEntity
{
    /// <summary>
    /// 浏览统计
    /// </summary>
    public partial class tab_Statistics : IEntity
    {
        /// <summary>
        /// 周期统计
        /// </summary>
        /// <param name="IntervalChar">d:天 ww:周 m:月 yyyy:年</param>
        /// <param name="IntervalNum">几个周期</param>
        /// <returns></returns>
        public static int CycCount(string IntervalChar, int IntervalNum)
        {
            return DataEntity.Common.ExecuteScalar<int>(string.Format(
                "select Count(*) from tab_Statistics where DateDiff('{0}', sta_VisitDate, Date()) <= {1}", IntervalChar, IntervalNum),
                null, null);
        }

        /// <summary>
        /// 周期统计(日期范围)
        /// </summary>        
        public static int CycCount(DateTime StartDate, DateTime EndDate)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("select Count(*) from tab_Statistics where 1 = 1 ");
            List<string> para_keys = new List<string>();
            List<object> para_vals = new List<object>();

            if (StartDate != DateTime.MinValue)
            {
                sb.Append(" AND sta_VisitDate >= @StartDate");
                para_keys.Add("@StartDate");
                para_vals.Add(StartDate);
            }

            if (EndDate != DateTime.MinValue)
            {
                sb.Append(" AND sta_VisitDate <= @EndDate");
                para_keys.Add("@EndDate");
                para_vals.Add(EndDate);
            }

            return DataEntity.Common.ExecuteScalar<int>(sb.ToString(), para_keys.ToArray(), para_vals.ToArray());
        }
    }
}

